package me.zhengjie.modules.security.rest;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.security.service.WxLoginService;
import me.zhengjie.modules.security.service.dto.AuthUserDto;
import me.zhengjie.modules.security.service.dto.JwtUserDto;
import me.zhengjie.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 授权、根据token获取用户详细信息
 */
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
@Tag(name = "系统：系统授权接口")
public class AuthController {

    private static final Logger log = LoggerFactory.getLogger(AuthController.class);
    private final WxLoginService wxLoginService;
    
    /**
     * 获取微信授权URL
     */
    @Operation(summary = "获取微信授权URL")
    @GetMapping("/wxLogin")
    public ResponseEntity<String> wxLogin() {
        return ResponseEntity.ok(wxLoginService.getWxAuthUrl());
    }
    
    /**
     * 微信登录回调
     */
    @Operation(summary = "微信登录回调")
    @GetMapping("/wxCallback")
    public ResponseEntity<Map<String, Object>> wxCallback(@RequestParam String code, @RequestParam String state) {
        return ResponseEntity.ok(wxLoginService.wxCallback(code, state));
    }

    @Operation(summary = "微信登录服务器验证")
    @GetMapping("/verify")
    public String verify(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, @RequestParam String echostr) {
        return echostr;
    }
}
